package com.haifeng.asms.api.handler;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.haifeng.asms.api.properties.SystemProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * <p>
 *  项目初始化
 * </p>
 *
 * @author: Haifeng
 * @date: 2020-06-21
 */
@Slf4j
@Component
@AllArgsConstructor
public class Inithandler implements ApplicationRunner {

    private final SystemProperties systemProperties;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        // 1、初始化上传文件的目录
        String filePath = systemProperties.getFilePath();
        if (StrUtil.isBlank(filePath)){
            return;
        }
        if (!FileUtil.exist(filePath)){
            boolean mkdirs = new File(filePath).mkdirs();
            log.info("初始化上传文件目录{}：{}", mkdirs ? "成功" : "失败",filePath);
        }
    }
}
